/*     */ package com.zimbra.cs.mailbox.calendar;
/*     */ 
/*     */ import com.zimbra.common.calendar.CalendarUtil;
/*     */ import com.zimbra.common.calendar.ZCalendar.ICalTok;
/*     */ import com.zimbra.common.calendar.ZCalendar.ZParameter;
/*     */ import com.zimbra.common.calendar.ZCalendar.ZProperty;
/*     */ import com.zimbra.common.mime.shim.JavaMailInternetAddress;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.IDNUtil;
/*     */ import com.zimbra.cs.mailbox.Metadata;
/*     */ import com.zimbra.cs.service.mail.ToXML;
/*     */ import com.zimbra.soap.mail.type.CalendarAttendee;
/*     */ import java.util.List;
/*     */ import javax.mail.Address;
/*     */ import javax.mail.internet.AddressException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ZAttendee
/*     */   extends CalendarUser
/*     */ {
/*     */   private static final String FN_CUTYPE = "cut";
/*     */   private static final String FN_ROLE = "r";
/*     */   private static final String FN_PARTSTAT = "ptst";
/*     */   private static final String FN_RSVP_BOOL = "v";
/*     */   private static final String FN_MEMBER = "member";
/*     */   private static final String FN_DELEGATED_TO = "delto";
/*     */   private static final String FN_DELEGATED_FROM = "delfrom";
/*     */   private String mCUType;
/*     */   private String mRole;
/*     */   private String mPartStat;
/*     */   private Boolean mRsvp;
/*     */   private String mMember;
/*     */   private String mDelegatedTo;
/*     */   private String mDelegatedFrom;
/*     */   
/*  57 */   public boolean hasCUType() { return !StringUtil.isNullOrEmpty(this.mCUType); }
/*  58 */   public String getCUType() { return this.mCUType != null ? this.mCUType : ""; }
/*     */   
/*  60 */   public void setCUType(String cutype) { if ((cutype != null) && (!IcalXmlStrMap.sCUTypeMap.validXml(cutype))) {
/*  61 */       cutype = IcalXmlStrMap.sCUTypeMap.toXml(cutype);
/*     */     }
/*  63 */     this.mCUType = cutype;
/*     */   }
/*     */   
/*  66 */   public boolean hasRole() { return !StringUtil.isNullOrEmpty(this.mRole); }
/*  67 */   public String getRole() { return this.mRole != null ? this.mRole : ""; }
/*     */   
/*  69 */   public void setRole(String role) { if ((role != null) && (!IcalXmlStrMap.sRoleMap.validXml(role))) {
/*  70 */       role = IcalXmlStrMap.sRoleMap.toXml(role);
/*     */     }
/*  72 */     this.mRole = role;
/*     */   }
/*     */   
/*  75 */   public boolean hasPartStat() { return !StringUtil.isNullOrEmpty(this.mPartStat); }
/*  76 */   public String getPartStat() { return this.mPartStat != null ? this.mPartStat : ""; }
/*     */   
/*  78 */   public void setPartStat(String partStat) { if ((partStat != null) && (!IcalXmlStrMap.sPartStatMap.validXml(partStat))) {
/*  79 */       partStat = IcalXmlStrMap.sPartStatMap.toXml(partStat);
/*     */     }
/*  81 */     this.mPartStat = partStat;
/*     */   }
/*     */   
/*  84 */   public boolean hasRsvp() { return this.mRsvp != null; }
/*  85 */   public Boolean getRsvp() { return this.mRsvp; }
/*  86 */   public void setRsvp(Boolean rsvp) { this.mRsvp = rsvp; }
/*     */   
/*  88 */   public boolean hasMember() { return !StringUtil.isNullOrEmpty(this.mMember); }
/*  89 */   public String getMember() { return this.mMember; }
/*  90 */   public void setMember(String member) { this.mMember = getMailToAddress(member); }
/*     */   
/*  92 */   public boolean hasDelegatedTo() { return !StringUtil.isNullOrEmpty(this.mDelegatedTo); }
/*  93 */   public String getDelegatedTo() { return this.mDelegatedTo; }
/*  94 */   public void setDelegatedTo(String delTo) { this.mDelegatedTo = getMailToAddress(delTo); }
/*     */   
/*  96 */   public boolean hasDelegatedFrom() { return !StringUtil.isNullOrEmpty(this.mDelegatedFrom); }
/*  97 */   public String getDelegatedFrom() { return this.mDelegatedFrom; }
/*  98 */   public void setDelegatedFrom(String delFrom) { this.mDelegatedFrom = getMailToAddress(delFrom); }
/*     */   
/*     */   public ZAttendee(ZAttendee other) {
/* 101 */     super(other);
/* 102 */     this.mCUType = other.mCUType;
/* 103 */     this.mRole = other.mRole;
/* 104 */     this.mPartStat = other.mPartStat;
/* 105 */     this.mRsvp = other.mRsvp;
/* 106 */     this.mMember = other.mMember;
/* 107 */     this.mDelegatedTo = other.mDelegatedTo;
/* 108 */     this.mDelegatedFrom = other.mDelegatedFrom;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public ZAttendee(String address, String cn, String sentBy, String dir, String language, String cutype, String role, String ptst, Boolean rsvp, String member, String delegatedTo, String delegatedFrom, List<ZCalendar.ZParameter> xparams)
/*     */   {
/* 124 */     super(address, cn, sentBy, dir, language, xparams);
/* 125 */     setCUType(cutype);
/* 126 */     setRole(role);
/* 127 */     setPartStat(ptst);
/* 128 */     setRsvp(rsvp);
/* 129 */     setMember(member);
/* 130 */     setDelegatedTo(delegatedTo);
/* 131 */     setDelegatedFrom(delegatedFrom);
/*     */   }
/*     */   
/*     */   public ZAttendee(String address) {
/* 135 */     this(address, null, null, null, null, null, null, null, null, null, null, null, null);
/*     */   }
/*     */   
/*     */   public ZAttendee(ZCalendar.ZProperty prop)
/*     */   {
/* 140 */     super(prop);
/* 141 */     setCUType(prop.paramVal(ZCalendar.ICalTok.CUTYPE, null));
/* 142 */     setRole(prop.paramVal(ZCalendar.ICalTok.ROLE, null));
/* 143 */     setPartStat(prop.paramVal(ZCalendar.ICalTok.PARTSTAT, null));
/*     */     
/* 145 */     String rsvpStr = prop.paramVal(ZCalendar.ICalTok.RSVP, "FALSE");
/* 146 */     boolean rsvp = false;
/* 147 */     if (rsvpStr.equalsIgnoreCase("TRUE"))
/* 148 */       rsvp = true;
/* 149 */     setRsvp(Boolean.valueOf(rsvp));
/*     */     
/* 151 */     setMember(prop.paramVal(ZCalendar.ICalTok.MEMBER, null));
/* 152 */     setDelegatedTo(prop.paramVal(ZCalendar.ICalTok.DELEGATED_TO, null));
/* 153 */     setDelegatedFrom(prop.paramVal(ZCalendar.ICalTok.DELEGATED_FROM, null));
/*     */   }
/*     */   
/*     */   public ZAttendee(Metadata meta) throws ServiceException {
/* 157 */     super(meta);
/* 158 */     setCUType(meta.get("cut", null));
/* 159 */     setRole(meta.get("r", null));
/* 160 */     setPartStat(meta.get("ptst", null));
/*     */     
/* 162 */     Boolean rsvp = null;
/* 163 */     if (meta.containsKey("v")) {
/* 164 */       if (meta.getBool("v")) {
/* 165 */         rsvp = Boolean.TRUE;
/*     */       } else
/* 167 */         rsvp = Boolean.FALSE;
/*     */     }
/* 169 */     setRsvp(rsvp);
/*     */     
/* 171 */     setMember(meta.get("member", null));
/* 172 */     setDelegatedTo(meta.get("delto", null));
/* 173 */     setDelegatedFrom(meta.get("delfrom", null));
/*     */   }
/*     */   
/*     */   public Metadata encodeAsMetadata() {
/* 177 */     Metadata meta = super.encodeMetadata();
/* 178 */     if (hasCUType())
/* 179 */       meta.put("cut", getCUType());
/* 180 */     if (hasRole())
/* 181 */       meta.put("r", getRole());
/* 182 */     if (hasPartStat())
/* 183 */       meta.put("ptst", getPartStat());
/* 184 */     if ((hasRsvp()) && (getRsvp().booleanValue()))
/* 185 */       meta.put("v", "1");
/* 186 */     if (hasMember())
/* 187 */       meta.put("member", getMember());
/* 188 */     if (hasDelegatedTo())
/* 189 */       meta.put("delto", getDelegatedTo());
/* 190 */     if (hasDelegatedFrom()) {
/* 191 */       meta.put("delfrom", getDelegatedFrom());
/*     */     }
/* 193 */     return meta;
/*     */   }
/*     */   
/*     */   protected ZCalendar.ICalTok getPropertyName()
/*     */   {
/* 198 */     return ZCalendar.ICalTok.ATTENDEE;
/*     */   }
/*     */   
/*     */   protected void setProperty(ZCalendar.ZProperty prop) throws ServiceException
/*     */   {
/* 203 */     super.setProperty(prop);
/* 204 */     if (hasCUType())
/* 205 */       prop.addParameter(new ZCalendar.ZParameter(ZCalendar.ICalTok.CUTYPE, IcalXmlStrMap.sCUTypeMap.toIcal(getCUType())));
/* 206 */     if (hasRole())
/* 207 */       prop.addParameter(new ZCalendar.ZParameter(ZCalendar.ICalTok.ROLE, IcalXmlStrMap.sRoleMap.toIcal(getRole())));
/* 208 */     if (hasPartStat())
/* 209 */       prop.addParameter(new ZCalendar.ZParameter(ZCalendar.ICalTok.PARTSTAT, IcalXmlStrMap.sPartStatMap.toIcal(getPartStat())));
/* 210 */     if (hasRsvp())
/*     */     {
/*     */ 
/* 213 */       if ("NE".equals(getPartStat())) {
/* 214 */         prop.addParameter(new ZCalendar.ZParameter(ZCalendar.ICalTok.RSVP, getRsvp().booleanValue()));
/*     */       }
/*     */     }
/* 217 */     if (hasMember())
/* 218 */       prop.addParameter(new ZCalendar.ZParameter(ZCalendar.ICalTok.MEMBER, "MAILTO:" + getMember()));
/* 219 */     if (hasDelegatedTo())
/* 220 */       prop.addParameter(new ZCalendar.ZParameter(ZCalendar.ICalTok.DELEGATED_TO, "MAILTO:" + getDelegatedTo()));
/* 221 */     if (hasDelegatedFrom()) {
/* 222 */       prop.addParameter(new ZCalendar.ZParameter(ZCalendar.ICalTok.DELEGATED_FROM, "MAILTO:" + getDelegatedFrom()));
/*     */     }
/*     */   }
/*     */   
/*     */   protected StringBuilder addToStringBuilder(StringBuilder sb) {
/* 227 */     if (hasCUType()) {
/* 228 */       if (sb.length() > 0) sb.append(';');
/* 229 */       sb.append("CUTYPE=").append(getCUType());
/*     */     }
/* 231 */     if (hasRole()) {
/* 232 */       if (sb.length() > 0) sb.append(';');
/* 233 */       sb.append("ROLE=").append(getRole());
/*     */     }
/* 235 */     if (hasPartStat()) {
/* 236 */       if (sb.length() > 0) sb.append(';');
/* 237 */       sb.append("PARTSTAT=").append(getPartStat());
/*     */     }
/* 239 */     if (hasRsvp()) {
/* 240 */       if (sb.length() > 0) sb.append(';');
/* 241 */       sb.append("RSVP=");
/* 242 */       if (getRsvp().booleanValue()) {
/* 243 */         sb.append("TRUE");
/*     */       } else
/* 245 */         sb.append("FALSE");
/*     */     }
/* 247 */     if (hasMember()) {
/* 248 */       if (sb.length() > 0) sb.append(';');
/* 249 */       sb.append("MEMBER=\"MAILTO:").append(getMember()).append('"');
/*     */     }
/* 251 */     if (hasDelegatedTo()) {
/* 252 */       if (sb.length() > 0) sb.append(';');
/* 253 */       sb.append("DELEGATED-TO=\"MAILTO:").append(getDelegatedTo()).append('"');
/*     */     }
/* 255 */     if (hasDelegatedTo()) {
/* 256 */       if (sb.length() > 0) sb.append(';');
/* 257 */       sb.append("DELEGATED-FROM=\"MAILTO:").append(getDelegatedFrom()).append('"');
/*     */     }
/*     */     
/* 260 */     sb = super.addToStringBuilder(sb);
/* 261 */     return sb;
/*     */   }
/*     */   
/*     */   public boolean addressesMatch(ZAttendee other) {
/* 265 */     return getAddress().equalsIgnoreCase(other.getAddress());
/*     */   }
/*     */   
/*     */   public boolean addressMatches(String addr) {
/* 269 */     return getAddress().equalsIgnoreCase(addr);
/*     */   }
/*     */   
/*     */   public boolean addressMatches(Address address) {
/* 273 */     if (address == null) {
/* 274 */       ZimbraLog.calendar.debug("addressMatches called with 'null' - can never match Zattendee '%s'", new Object[] { this });
/* 275 */       return false;
/*     */     }
/*     */     try
/*     */     {
/* 279 */       JavaMailInternetAddress jmia = new JavaMailInternetAddress(address.toString(), true);
/* 280 */       return getAddress().equalsIgnoreCase(jmia.getAddress());
/*     */     } catch (AddressException e) {
/* 282 */       ZimbraLog.calendar.debug("problem matching address '%s' against Zattendee '%s'", address, this, e); }
/* 283 */     return false;
/*     */   }
/*     */   
/*     */   public CalendarAttendee toJaxb()
/*     */   {
/* 288 */     CalendarAttendee attendee = new CalendarAttendee();
/*     */     
/* 290 */     attendee.setAddress(IDNUtil.toUnicode(getAddress()));
/* 291 */     attendee.setUrl(getAddress());
/*     */     
/* 293 */     if (hasCn()) {
/* 294 */       attendee.setDisplayName(getCn());
/*     */     }
/* 296 */     if (hasSentBy()) {
/* 297 */       attendee.setSentBy(getSentBy());
/*     */     }
/* 299 */     if (hasDir()) {
/* 300 */       attendee.setDir(getDir());
/*     */     }
/* 302 */     if (hasLanguage()) {
/* 303 */       attendee.setLanguage(getLanguage());
/*     */     }
/* 305 */     if (hasCUType()) {
/* 306 */       attendee.setCuType(getCUType());
/*     */     }
/* 308 */     if (hasRole()) {
/* 309 */       attendee.setRole(getRole());
/*     */     }
/* 311 */     if (hasPartStat()) {
/* 312 */       attendee.setPartStat(getPartStat());
/*     */     }
/* 314 */     if (hasRsvp()) {
/* 315 */       attendee.setRsvp(getRsvp());
/*     */     }
/* 317 */     if (hasMember()) {
/* 318 */       attendee.setMember(getMember());
/*     */     }
/* 320 */     if (hasDelegatedTo()) {
/* 321 */       attendee.setDelegatedTo(getDelegatedTo());
/*     */     }
/* 323 */     if (hasDelegatedFrom()) {
/* 324 */       attendee.setDelegatedFrom(getDelegatedFrom());
/*     */     }
/* 326 */     attendee.setXParams(ToXML.jaxbXParams(xparamsIterator()));
/* 327 */     return attendee;
/*     */   }
/*     */   
/*     */   public Element toXml(Element parent) {
/* 331 */     Element atElt = parent.addElement("at");
/*     */     
/* 333 */     atElt.addAttribute("a", IDNUtil.toUnicode(getAddress()));
/* 334 */     atElt.addAttribute("url", getAddress());
/*     */     
/* 336 */     if (hasCn()) {
/* 337 */       atElt.addAttribute("d", getCn());
/*     */     }
/* 339 */     if (hasSentBy()) {
/* 340 */       atElt.addAttribute("sentBy", getSentBy());
/*     */     }
/* 342 */     if (hasDir()) {
/* 343 */       atElt.addAttribute("dir", getDir());
/*     */     }
/* 345 */     if (hasLanguage()) {
/* 346 */       atElt.addAttribute("lang", getLanguage());
/*     */     }
/* 348 */     if (hasCUType()) {
/* 349 */       atElt.addAttribute("cutype", getCUType());
/*     */     }
/* 351 */     if (hasRole()) {
/* 352 */       atElt.addAttribute("role", getRole());
/*     */     }
/* 354 */     if (hasPartStat()) {
/* 355 */       atElt.addAttribute("ptst", getPartStat());
/*     */     }
/* 357 */     if (hasRsvp()) {
/* 358 */       atElt.addAttribute("rsvp", getRsvp().booleanValue());
/*     */     }
/* 360 */     if (hasMember()) {
/* 361 */       atElt.addAttribute("member", getMember());
/*     */     }
/* 363 */     if (hasDelegatedTo()) {
/* 364 */       atElt.addAttribute("delTo", getDelegatedTo());
/*     */     }
/* 366 */     if (hasDelegatedFrom()) {
/* 367 */       atElt.addAttribute("delFrom", getDelegatedFrom());
/*     */     }
/* 369 */     CalendarUtil.encodeXParams(atElt, xparamsIterator());
/*     */     
/* 371 */     return atElt;
/*     */   }
/*     */   
/*     */   public static ZAttendee parse(Element element) throws ServiceException {
/* 375 */     String address = IDNUtil.toAscii(element.getAttribute("a", null));
/* 376 */     if (address == null) {
/* 377 */       address = element.getAttribute("url", null);
/* 378 */       if (address == null) {
/* 379 */         throw ServiceException.INVALID_REQUEST("missing attendee address", null);
/*     */       }
/*     */     }
/* 382 */     String cn = element.getAttribute("d", null);
/* 383 */     String sentBy = element.getAttribute("sentBy", null);
/* 384 */     String dir = element.getAttribute("dir", null);
/* 385 */     String lang = element.getAttribute("lang", null);
/*     */     
/* 387 */     String cutype = element.getAttribute("cutype", null);
/* 388 */     if (cutype != null) {
/* 389 */       validateAttr(IcalXmlStrMap.sCUTypeMap, "cutype", cutype);
/*     */     }
/* 391 */     String role = element.getAttribute("role", null);
/* 392 */     if (role != null) {
/* 393 */       validateAttr(IcalXmlStrMap.sRoleMap, "role", role);
/*     */     }
/* 395 */     String partStat = element.getAttribute("ptst", null);
/* 396 */     if (partStat != null) {
/* 397 */       validateAttr(IcalXmlStrMap.sPartStatMap, "ptst", partStat);
/*     */     }
/*     */     
/* 400 */     String member = element.getAttribute("member", null);
/* 401 */     String delTo = element.getAttribute("delTo", null);
/* 402 */     String delFrom = element.getAttribute("delFrom", null);
/*     */     
/* 404 */     boolean rsvp = element.getAttributeBool("rsvp", false);
/*     */     
/*     */ 
/*     */ 
/* 408 */     List<ZCalendar.ZParameter> xparams = CalendarUtil.parseXParams(element);
/*     */     
/* 410 */     ZAttendee at = new ZAttendee(address, cn, sentBy, dir, lang, cutype, role, partStat, rsvp ? Boolean.TRUE : Boolean.FALSE, member, delTo, delFrom, xparams);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 416 */     return at;
/*     */   }
/*     */   
/*     */   private static void validateAttr(IcalXmlStrMap map, String attrName, String value) throws ServiceException
/*     */   {
/* 421 */     if (!map.validXml(value)) {
/* 422 */       throw ServiceException.INVALID_REQUEST("Invalid value '" + value + "' specified for attribute:" + attrName, null);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/calendar/ZAttendee.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */